﻿using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace MESPro.Controls
{
    /// <summary>
    /// 返回文件名(不包含路径,包含扩展名)
    /// </summary>
    public class PropertyReturnFileName : UITypeEditor
    {
        #region Public 方法

        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.
IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc =
                (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                // 可以打开任何特定的对话框

                OpenFileDialog dialog = new OpenFileDialog();
                dialog.InitialDirectory = System.Windows.Forms.Application.StartupPath + "\\img";
                dialog.AddExtension = false;

                if (dialog.ShowDialog().Equals(DialogResult.OK))
                {
                    //ControlProperty controlProperty = new ControlProperty();
                    //controlProperty.ImageKey = dialog.FileName;
                    return dialog.SafeFileName;
                }
            }

            return value;
        }

        #endregion Public 方法
    }
}